package tp.pr5.items;

import tp.pr5.NavigationModule;
import tp.pr5.RobotEngine;

public class Bomb extends Item 
{
	private boolean activated = false;
	private int damage;
	private int requirement;
	
	public Bomb(String id, String description, int damage, int requirement, boolean activated)
	{
		super(id, description);
		this.activated = activated;
		this.damage = damage;
		this.requirement = requirement;
	}

	@Override
	public boolean canBeUsed() 
	{
		return this.activated;
	}

	@Override
	public boolean use(RobotEngine r, NavigationModule nav) 
	{
		if(r.getFuel() >= this.requirement)
		{
			r.addFuel(-this.requirement);
			if(this.activated)
			{
				this.activated = false;
			}
			else
			{
				this.activated = true;
			}
			return true;
		}	
		return false;
	}
	
	public String toString()
	{
		return super.toString() + " // damage = " + this.damage + ", requirement fuel = " + this.requirement + ", state = " + state();
	}
	
	private String state()
	{
		if(this.activated)
		{
			return "on";
		}
		return "off";
	}

	@Override
	public boolean canBeDefused() 
	{
		return canBeUsed();
	}

	@Override
	public int explode()
	{
		return this.damage;
	}

}
